package com.Date3;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

public class Test {
    public static void main(String[] args) {
        //先创建对象，完成实例化
        //方法1：now()-获取当前日期，时间，日期T时间
        LocalDate d1 = LocalDate.now();
        LocalTime t1 = LocalTime.now();
        LocalDateTime dt1 = LocalDateTime.now();
        System.out.println(d1);
        System.out.println(t1);
        System.out.println(dt1);
        //方法2：of()-设置指定的日期，时间，日期时间
        LocalDate d2 = LocalDate.of(2021,8,20);
        LocalTime t2 = LocalTime.of(20,48,59,99);
        LocalDateTime dt2 = LocalDateTime.of(2021,8,20,20,47,54,49);
        System.out.println(d2);
        System.out.println(t2);
        System.out.println(dt2);

        //用LocalDateTime
        //get
        System.out.println(dt1.getYear());  //2021
        System.out.println(dt1.getMonth()); //AUGUST
        System.out.println(dt1.getMonthValue()); //8
        System.out.println(dt1.getDayOfMonth()); //20
        System.out.println(dt1.getDayOfWeek());   //FRIDAY
        System.out.println(dt1.getHour());   //20
        System.out.println(dt1.getMinute());  //55
        System.out.println(dt1.getSecond());   //58

        //set方法，这里不叫set，叫with方法
        //重新改的时候，改的是新的时间，而不是之前的对象
        LocalDateTime dt3 = dt1.withMonth(9);
        System.out.println(dt1);
        System.out.println(dt3);


        LocalDateTime dt4 = dt1.plusMonths(4);
        System.out.println(dt4);

        LocalDateTime dt5 = dt1.minusMonths(5);
        System.out.println(dt5);


    }
}
